/*     */ package com.controller.front;
/*     */ 
/*     */ import base.dao.BaseExample;
/*     */ import base.dao.BaseExample.Criteria;
/*     */ import base.utils.MD5Util;
/*     */ import base.utils.MailUtil;
/*     */ import base.utils.ResultUtil;
/*     */ import base.utils.UUIDUtil;
/*     */ import com.model.Admin;
/*     */ import com.model.Users;
/*     */ import com.service.UserService;
/*     */ import java.io.PrintStream;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import javax.servlet.http.HttpSession;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"user"})
/*     */ public class UserController
/*     */ {
/*  38 */   protected Logger log = Logger.getLogger(UserController.class);
/*     */   
/*     */   @Autowired
/*     */   private UserService userService;
/*     */   public static final int TIMELIMIT = 86400000;
/*     */   
/*     */   public static Date getNextDay(Date date)
/*     */   {
/*  46 */     Calendar calendar = Calendar.getInstance();
/*  47 */     calendar.setTime(date);
/*  48 */     calendar.add(5, 1);
/*  49 */     date = calendar.getTime();
/*  50 */     return date;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"regist"})
/*     */   public ModelAndView regist(HttpServletRequest request)
/*     */   {
/*  61 */     ModelAndView mv = new ModelAndView();
/*  62 */     Map<String, Object> attributes = new HashMap();
/*  63 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try
/*     */     {
/*  66 */       String username = new String(request.getParameter("name").getBytes("ISO-8859-1"), "utf-8");
/*     */       
/*  68 */       String unit = new String(request.getParameter("unit").getBytes("ISO-8859-1"), "utf-8");
/*     */       
/*  70 */       String identitytype = request.getParameter("identity");
/*  71 */       String email = request.getParameter("email");
/*  72 */       String password = request.getParameter("password");
/*     */       
/*  74 */       this.log.info("regist username " + username);
/*     */       
/*  76 */       if (("".equals(username)) || (username == null)) {
/*  77 */         Map<String, Object> map = new HashMap();
/*  78 */         return ResultUtil.returnJsonStr("1", "name参数为空", attributes, map, view, mv);
/*     */       }
/*  80 */       if (("".equals(unit)) || (unit == null)) {
/*  81 */         Map<String, Object> map = new HashMap();
/*  82 */         return ResultUtil.returnJsonStr("1", "unit参数为空", attributes, map, view, mv);
/*     */       }
/*  84 */       if (("".equals(identitytype)) || (identitytype == null)) {
/*  85 */         Map<String, Object> map = new HashMap();
/*  86 */         return ResultUtil.returnJsonStr("1", "identitytype参数为空", attributes, map, view, mv);
/*     */       }
/*  88 */       if (("".equals(email)) || (email == null)) {
/*  89 */         Map<String, Object> map = new HashMap();
/*  90 */         return ResultUtil.returnJsonStr("1", "email参数为空", attributes, map, view, mv);
/*     */       }
/*  92 */       if ((password == null) || ("".equals(password))) {
/*  93 */         Map<String, Object> map = new HashMap();
/*  94 */         return ResultUtil.returnJsonStr("1", "password参数为空", attributes, map, view, mv);
/*     */       }
/*  96 */       BaseExample be = new BaseExample();
/*  97 */       be.or().andEqualTo("deleteFlag", Integer.valueOf(0)).andEqualTo("user_email", email);
/*  98 */       List<Map<?, ?>> resList = this.userService.selectByExample(be);
/*     */       
/*     */ 
/* 101 */       if (resList.size() > 0) {
/* 102 */         Map<String, Object> map = new HashMap();
/* 103 */         return ResultUtil.returnJsonStr("1", "该邮箱已被注册", attributes, map, view, mv);
/*     */       }
/*     */       
/* 106 */       Users user = new Users();
/* 107 */       user.setCreateTime(new Date());
/* 108 */       user.setDeleteFlag(0);
/* 109 */       user.setUser_name(username);
/* 110 */       user.setUser_email(email);
/* 111 */       user.setUser_unit(unit);
/* 112 */       user.setPassword(password);
/* 113 */       user.setCreateTime(new Date());
/*     */       
/* 115 */       Date curTime = new Date();
/* 116 */       user.setActuraTime(getNextDay(curTime));
/* 117 */       user.setUser_identityType(identitytype);
/* 118 */       if ("1".equals(identitytype)) {
/* 119 */         user.setUser_identityCount("student");
/* 120 */       } else if ("2".equals(identitytype)) {
/* 121 */         user.setUser_identityCount("professor");
/*     */       }
/* 123 */       user.setRegistId("");
/* 124 */       user.setUser_type(1);
/* 125 */       Map<String, Object> map = new HashMap();
/* 126 */       map.put("user", user);
/* 127 */       String code = MD5Util.ccMD5(email) + UUIDUtil.getUUID();
/* 128 */       user.setRegistId(code);
/* 129 */       MailUtil.sendMail(user.getUser_email(), user.getRegistId());
/* 130 */       int insertByEntity = this.userService.insertByEntity(user);
/* 131 */       this.log.info("regist insertByEntity " + insertByEntity);
/* 132 */       return ResultUtil.returnJsonStr("0", "注册成功，请前往邮箱激活。", attributes, map, view, mv);
/*     */     }
/*     */     catch (Exception e) {
/* 135 */       e.printStackTrace();
/* 136 */       Map<String, Object> map = new HashMap();
/* 137 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"forgetPwd"})
/*     */   public ModelAndView forgetPwd(HttpServletRequest request)
/*     */   {
/* 149 */     ModelAndView mv = new ModelAndView();
/* 150 */     Map<String, Object> attributes = new HashMap();
/* 151 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try {
/* 153 */       String email = request.getParameter("email");
/* 154 */       String password = request.getParameter("password");
/*     */       
/* 156 */       if (("".equals(email)) || (email == null)) {
/* 157 */         Map<String, Object> map = new HashMap();
/* 158 */         return ResultUtil.returnJsonStr("1", "email参数为空", attributes, map, view, mv);
/*     */       }
/* 160 */       if (("".equals(password)) || (password == null)) {
/* 161 */         Map<String, Object> map = new HashMap();
/* 162 */         return ResultUtil.returnJsonStr("1", "password参数为空", attributes, map, view, mv);
/*     */       }
/*     */       
/* 165 */       BaseExample be = new BaseExample();
/* 166 */       be.or().andEqualTo("deleteFlag", Integer.valueOf(0)).andEqualTo("user_email", email).andEqualTo("user_type", Integer.valueOf(0));
/* 167 */       List<Map<?, ?>> resList = this.userService.selectByExample(be);
/* 168 */       if (resList.size() > 0) {
/* 169 */         String user_id = ((Map)resList.get(0)).get("user_id").toString();
/* 170 */         Users user = (Users)this.userService.selectByPrimaryKey(user_id);
/* 171 */         String code = MD5Util.ccMD5(email) + UUIDUtil.getUUID();
/* 172 */         user.setRegistId(code);
/* 173 */         MailUtil.findPasswordMail(email, user.getRegistId(), password);
/* 174 */         this.userService.updateByEntity(user);
/* 175 */         Map<String, Object> map = new HashMap();
/* 176 */         return ResultUtil.returnJsonStr("0", "请前往邮箱完成验证。", attributes, map, view, mv);
/*     */       }
/* 178 */       return ResultUtil.returnJsonStr("1", "此邮箱未激活", attributes, new HashMap(), view, mv);
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 182 */       e.printStackTrace(); }
/* 183 */     return ResultUtil.returnJsonStr("1", "系统错误", attributes, new HashMap(), view, mv);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"check"})
/*     */   public ModelAndView modeifyactive(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 194 */     ModelAndView mv = new ModelAndView();
/*     */     
/* 196 */     String code = request.getParameter("code");
/* 197 */     String password = request.getParameter("password");
/*     */     
/* 199 */     BaseExample be = new BaseExample();
/*     */     
/* 201 */     be.or().andEqualTo("deleteFlag", Integer.valueOf(0)).andEqualTo("registId", code);
/* 202 */     List<Map<?, ?>> resList = this.userService.selectByExample(be);
/* 203 */     Users u = null;
/* 204 */     for (Map<?, ?> map : resList) {
/* 205 */       int id = ((Integer)map.get("user_id")).intValue();
/* 206 */       String user_id = id+"";
/* 207 */       u = (Users)this.userService.selectByPrimaryKey(user_id);
/* 208 */       if (u != null) {
/* 209 */         u.setRegistId("");
/* 210 */         u.setUser_type(0);
/* 211 */         u.setPassword(password);
/* 212 */         this.userService.updateByEntity(u);
/* 213 */         mv.setViewName("/welcome.jsp");
/*     */       } else {
/* 215 */         mv.setViewName("/fail.jsp");
/*     */       }
/*     */     }
/* 218 */     return mv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"active"})
/*     */   public ModelAndView active(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 227 */     ModelAndView mv = new ModelAndView();
/*     */     
/* 229 */     String code = request.getParameter("code");
/* 230 */     Date time = new Date();
/* 231 */     BaseExample be = new BaseExample();
/* 232 */     be.or().andEqualTo("deleteFlag", Integer.valueOf(0)).andEqualTo("registId", code);
/* 233 */     List<Map<?, ?>> resList = this.userService.selectByExample(be);
/* 234 */     Users u = null;
/* 235 */     for (Map<?, ?> map : resList) {
/* 236 */       int id = ((Integer)map.get("user_id")).intValue();
/* 237 */       String user_id = id+"";
/* 238 */       u = (Users)this.userService.selectByPrimaryKey(user_id);
/* 239 */       if (u.getActuraTime().getTime() < time.getTime())
/*     */       {
/* 241 */         u.setActuraTime(null);
/* 242 */         u.setRegistId("");
/* 243 */         u.setDeleteFlag(1);
/* 244 */         mv.setViewName("/jihuoshibai.jsp");
/* 245 */         return mv;
/*     */       }
/* 247 */       if (u != null) {
/* 248 */         u.setRegistId("");
/* 249 */         u.setUser_type(0);
/* 250 */         this.userService.updateByEntity(u);
/* 251 */         mv.setViewName("/jihuo.jsp");
/*     */       } else {
/* 253 */         mv.setViewName("/jihuoshibai.jsp");
/*     */       }
/*     */     }
/*     */     
/* 257 */     return mv;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @RequestMapping({"login"})
/*     */   public ModelAndView login(HttpServletRequest request)
/*     */   {
/* 267 */     ModelAndView mv = new ModelAndView();
/* 268 */     Map<String, Object> attributes = new HashMap();
/* 269 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try {
/* 271 */       String email = request.getParameter("email");
/* 272 */       String password = request.getParameter("password");
/* 273 */       if (("".equals(email)) || (email == null)) {
/* 274 */         Map<String, Object> map = new HashMap();
/* 275 */         return ResultUtil.returnJsonStr("1", "email参数为空", attributes, map, view, mv);
/*     */       }
/* 277 */       if (("".equals(password)) || (password == null)) {
/* 278 */         Map<String, Object> map = new HashMap();
/* 279 */         return ResultUtil.returnJsonStr("1", "password参数为空", attributes, map, view, mv);
/*     */       }
/*     */       
/* 282 */       BaseExample be = new BaseExample();
/* 283 */       be.or().andEqualTo("deleteFlag", "0").andEqualTo("user_email", email).andEqualTo("password", password);
/* 284 */       List<Map<?, ?>> resList = this.userService.selectByExample(be);
/* 285 */       this.log.info("resList " + resList);
/* 286 */       if ((resList == null) || (resList.size() == 0)) {
/* 287 */         Map<String, Object> map = new HashMap();
/* 288 */         return ResultUtil.returnJsonStr("1", "账号或密码错误", attributes, map, view, mv);
/*     */       }
/* 290 */       BaseExample ba = new BaseExample();
/* 291 */       ba.or().andEqualTo("user_type", Integer.valueOf(1)).andEqualTo("deleteFlag", "0").andEqualTo("user_email", email).andEqualTo("password", password);
/* 292 */       List<Map<?, ?>> resList1 = this.userService.selectByExample(ba);
/* 293 */       if ((resList1 != null) && (resList1.size() != 0))
/*     */       {
/*     */ 
/* 296 */         return ResultUtil.returnJsonStr("1", "This mailbox is not activated", attributes, new HashMap(), view, mv);
/*     */       }
/* 298 */       String user_id = ((Map)resList.get(0)).get("user_id").toString();
/* 299 */       Users user = (Users)this.userService.selectByPrimaryKey(user_id);
/* 300 */       HttpSession session = request.getSession();
/* 301 */       session.setAttribute(user.getUser_email(), user);
/*     */       
/*     */ 
/* 304 */       Map<String, Object> map = new HashMap();
/* 305 */       map.put("user", user);
/* 306 */       return ResultUtil.returnJsonStr("0", "登录成功", attributes, map, view, mv);
/*     */ 
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 311 */       e.printStackTrace();
/* 312 */       Map<String, Object> map = new HashMap();
/* 313 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */   @RequestMapping({"check"})
/* 318 */   public ModelAndView check(HttpServletRequest request) { ModelAndView mv = new ModelAndView();
/* 319 */     Map<String, Object> attributes = new HashMap();
/* 320 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try
/*     */     {
/* 323 */       HttpSession session = request.getSession();
/* 324 */       Admin t = (Admin)session.getAttribute("user");
/* 325 */       if (t == null) {
/* 326 */         return ResultUtil.returnJsonStr("1", "未登录", attributes, new HashMap(), view, mv);
/*     */       }
/* 328 */       return ResultUtil.returnJsonStr("0", "已经登陆", attributes, new HashMap(), view, mv);
/*     */     }
/*     */     catch (Exception e) {
/* 331 */       e.printStackTrace();
/* 332 */       Map<String, Object> map = new HashMap();
/* 333 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */   @RequestMapping({"exc"})
/*     */   public ModelAndView exc(HttpServletRequest request) {
/* 339 */     ModelAndView mv = new ModelAndView();
/* 340 */     Map<String, Object> attributes = new HashMap();
/* 341 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/* 342 */     String user_email = request.getParameter("email");
/*     */     try {
/* 344 */       HttpSession session = request.getSession();
/* 345 */       session.removeAttribute(user_email);
/*     */       
/* 347 */       return ResultUtil.returnJsonStr("0", "退出登录", attributes, new HashMap(), view, mv);
/*     */     }
/*     */     catch (Exception e) {
/* 350 */       e.printStackTrace();
/* 351 */       Map<String, Object> map = new HashMap();
/* 352 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @RequestMapping({"getUserInfo"})
/*     */   public ModelAndView getUserInfo(HttpServletRequest request)
/*     */   {
/* 361 */     ModelAndView mv = new ModelAndView();
/* 362 */     Map<String, Object> attributes = new HashMap();
/* 363 */     MappingJacksonJsonView view = new MappingJacksonJsonView();
/*     */     try
/*     */     {
/* 366 */       String user_id = request.getParameter("user_id");
/* 367 */       if (("".equals(user_id)) || (user_id == null)) {
/* 368 */         Map<String, Object> map = new HashMap();
/* 369 */         return ResultUtil.returnJsonStr("1", "请先登录", attributes, map, view, mv);
/*     */       }
/* 371 */       Users user = (Users)this.userService.selectByPrimaryKey(user_id);
/* 372 */       if (user == null) {
/* 373 */         Map<String, Object> map = new HashMap();
/* 374 */         return ResultUtil.returnJsonStr("1", "没有该用户", attributes, map, view, mv);
/*     */       }
/* 376 */       Map<String, Object> map = new HashMap();
/* 377 */       map.put("user", user);
/* 378 */       return ResultUtil.returnJsonStr("0", "ok", attributes, map, view, mv);
/*     */     }
/*     */     catch (Exception e) {
/* 381 */       e.printStackTrace();
/* 382 */       Map<String, Object> map = new HashMap();
/* 383 */       return ResultUtil.returnJsonStr("1", "系统错误", attributes, map, view, mv);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/* 390 */     System.out.println("时间 " + new Date());
/*     */   }
/*     */ }


/* Location:              C:\Users\chengkp\Desktop\interwar\WEB-INF\classes\!\com\controller\front\UserController.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */